package com.linjiahao.commonUtil.Security;

/**
 * @Author linjiahao
 * @Date 2022/3/22 20:52
 * @Version 1.0
 */
public class RSATest {

    public static void main(String[] args) throws Exception {
       /* Map<String, Key> keyMap = RSAUtil.initKey();
        String publicKey = RSAUtil.getPublicKey(keyMap);
        String privateKey = RSAUtil.getPrivateKey(keyMap);
        System.out.println("公钥:"+publicKey);
        System.out.println("私钥"+privateKey);*/
        /**
        * PUBLIC_KEY:MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCP/S3sHM7awMus4F8C9Rgi3QEA3t5iOospIf8nLEypmkN4hYiPfmU3RqhM3cK5aXiuvoGfh4lbTEdT3GWjSUZYoqGyHu9uqWjrH2pqC9xBP8QDZIxy7FG/zU8Sfkc8Fk72d3PqRw5Hl3JID6ZLLzrDBqkfxzjSN6LT8j/oogSGXQIDAQAB
         * RSAPrivateKey:MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAI/9LewcztrAy6zgXwL1GCLdAQDe3mI6iykh/ycsTKmaQ3iFiI9+ZTdGqEzdwrlpeK6+gZ+HiVtMR1PcZaNJRliiobIe726paOsfamoL3EE/xANkjHLsUb/NTxJ+RzwWTvZ3c+pHDkeXckgPpksvOsMGqR/HONI3otPyP+iiBIZdAgMBAAECgYAKEbNvaohQpeDYYwxh4Y/hiED0taEpj1yB8N2t+JwX1DDZscTd/AHJ/sfwMCXY33ZQCgR4inrhhpEKXURCSfKATmOV+gHmuoEJml3cvWLyiWX87DqemRFuv5rU4KxJUFiqE5XaazQbD6o+x+70g+92Q+qNJrA/x6JyKIaBjpg05QJBAP1DMsztpp9WBZKHU2HCP//ALO+fonlgb/UaxJejf+r8N6V4q3iUin19O31gyy6QREJqL8teCDIacA3Qtl+i0tMCQQCRi5xVa9DXpYUBDAbl/94KMZ+0A9ZxfRSTk9n3VQfvG95dzKi2F4ZC1B+b8yOsp+obD3QwD2G9dmpRUlAVCaQPAkBrGDxmHeSEojqPALyIrTyk6F3YIlfxHY+aROx29wODmY3qYgGYZq+9avR6CzFACm9i6kY1qBitHzLdFLHZ9R9TAkB1ExVdDQ3/+S/EyNTfu/LyxjoNxqx/u7qKf3rsXiS0rPkxAIiReNjR9um6O1lt79/7hnHSmvznN1KMOacbVRb3AkB87GoajIvOZmLOpY8wwpZxuuUc3mCh/COvUyi5m2aFLV/7raXELD+3rl0Ry4WQi5sQMZHWFyi5Y3PHHW8nRV6D
        *
        * */
        String userId = "1508334484590764033";
        String key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCP/S3sHM7awMus4F8C9Rgi3QEA3t5iOospIf8nLEypmkN4hYiPfmU3RqhM3cK5aXiuvoGfh4lbTEdT3GWjSUZYoqGyHu9uqWjrH2pqC9xBP8QDZIxy7FG/zU8Sfkc8Fk72d3PqRw5Hl3JID6ZLLzrDBqkfxzjSN6LT8j/oogSGXQIDAQAB";
        String pkey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAI/9LewcztrAy6zgXwL1GCLdAQDe3mI6iykh/ycsTKmaQ3iFiI9+ZTdGqEzdwrlpeK6+gZ+HiVtMR1PcZaNJRliiobIe726paOsfamoL3EE/xANkjHLsUb/NTxJ+RzwWTvZ3c+pHDkeXckgPpksvOsMGqR/HONI3otPyP+iiBIZdAgMBAAECgYAKEbNvaohQpeDYYwxh4Y/hiED0taEpj1yB8N2t+JwX1DDZscTd/AHJ/sfwMCXY33ZQCgR4inrhhpEKXURCSfKATmOV+gHmuoEJml3cvWLyiWX87DqemRFuv5rU4KxJUFiqE5XaazQbD6o+x+70g+92Q+qNJrA/x6JyKIaBjpg05QJBAP1DMsztpp9WBZKHU2HCP//ALO+fonlgb/UaxJejf+r8N6V4q3iUin19O31gyy6QREJqL8teCDIacA3Qtl+i0tMCQQCRi5xVa9DXpYUBDAbl/94KMZ+0A9ZxfRSTk9n3VQfvG95dzKi2F4ZC1B+b8yOsp+obD3QwD2G9dmpRUlAVCaQPAkBrGDxmHeSEojqPALyIrTyk6F3YIlfxHY+aROx29wODmY3qYgGYZq+9avR6CzFACm9i6kY1qBitHzLdFLHZ9R9TAkB1ExVdDQ3/+S/EyNTfu/LyxjoNxqx/u7qKf3rsXiS0rPkxAIiReNjR9um6O1lt79/7hnHSmvznN1KMOacbVRb3AkB87GoajIvOZmLOpY8wwpZxuuUc3mCh/COvUyi5m2aFLV/7raXELD+3rl0Ry4WQi5sQMZHWFyi5Y3PHHW8nRV6D";
        String phoneText = RSAUtil.encryptByPublicKey(userId, key);
        System.out.println("加密后内容:" + phoneText);
        System.out.println("加密后长度:" + phoneText.length());
        System.out.println("解密后内容:" + new String(RSAUtil.decryptByPrivateKey(phoneText,pkey)));
    }
}
